package cn.cutie.clot.mq.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;

/**
 * @Description: mq消息对象
 * 消息一旦进入mq就是不变的
 * @Author: Cutie
 * @CreateDate: 2024/6/27 12:15
 * @Version: 0.0.1
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ClotMessage<T> {
//    private String topic;
    private Long id;
    private T body;
    // 消息的优先级，过期时间等系统属性：X-version = 1.0
    private Map<String, String> headers = new HashMap<>();
    // 业务属性
//    private Map<String, String> properties;
    static AtomicLong idgen = new AtomicLong(0);

    public static long nextId(){
        return idgen.getAndIncrement();
    }

    public static ClotMessage<?> create(Object body, Map<String, String> headers){
        return new ClotMessage<>(nextId(), body, headers);
    }
}
